package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.SubjectHub;

@Repository
public interface SubjectHubDao extends JpaRepository<SubjectHub, Integer>, JpaSpecificationExecutor<SubjectHub> {

	@Query("from SubjectHub where questionId = ?1")
	List<SubjectHub> find(String name);

	@Query("from SubjectHub where questionId like ?1")
	List<SubjectHub> findLike(String name);

	@Query(value = "select * from SubjectHub limit ?, ?", nativeQuery = true)
	List<SubjectHub> findPage(Integer offset, Integer size);

	@Query(value = "select * from SubjectHub where questionId = ? limit ?, ?", nativeQuery = true)
	List<SubjectHub> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from SubjectHub where questionId like ? limit ?, ?", nativeQuery = true)
	List<SubjectHub> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from SubjectHub where questionId = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from SubjectHub where questionId like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from SubjectHub order by id asc")
	List<SubjectHub> findAllAsc();

	@Query("select count( type ) from SubjectHub ")
	Integer countType();

	List<SubjectHub> findSubjectHubsByIdIn(List<Integer> idList);
}

